package link.wangkui.stream;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class ReduceTest {
    public static void main(String[] args) {

        List<ReduceBean> list=new ArrayList<>();

        ReduceBean user1=new ReduceBean();
        user1.setQty(1);
        user1.setWeight(new BigDecimal(100));
        list.add(user1);

        ReduceBean user2=new ReduceBean();
        user2.setQty(2);
        user2.setWeight(new BigDecimal(101));
        list.add(user2);

        ReduceBean u=list.stream().reduce((x,y)->{
            ReduceBean user=new ReduceBean();
            user.setQty(x.getQty()+ (y.getQty()));
            user.setWeight(x.getWeight().add(y.getWeight()));
            return user;
        }).get();
        System.out.println(u.getQty()+"------------"+u.getWeight());
    }
}
